package com.block;

import com.block.common.service.LogFactory;
import com.block.common.util.LocalDateUtil;
import com.block.dispos.ShutDownBean;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;



@EnableScheduling
@MapperScan("com.block.db.mapper")
@EnableDiscoveryClient
@EnableAsync
@SpringBootApplication(scanBasePackages = {"com.block.*", "com.market.*"})
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
public class ProviderApplication {
    private static final Logger log = LogFactory.getLog(ShutDownBean.class);

    @PostConstruct
    void started() {
        //指定时区
//        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

//       启动不初始化.此方法仅供数据异常时调用.
//        chainWalletUserService.initWalletAddress();
    }

    public static void main(String[] args) {
        try {
            ConfigurableApplicationContext context =
                    SpringApplication.run(ProviderApplication.class, args);
            Environment environment = context.getBean(Environment.class);
            System.out.println("localdate::::::::"+LocalDateUtil.getNowDateStr());
            log.info("项目启动成功" + environment.getProperty("local.server.port") +"环境参数:"+ environment.getProperty("spring.profiles.active"));
            Runtime.getRuntime().addShutdownHook(new Thread(() -> log.info("执行 ShutdownHook ...")));
        } catch (BeansException e) {
            e.printStackTrace();
            log.error("启动异常",e);
        }

    }


}
